package org.fanjr.simplify.rest.factory;

import org.fanjr.simplify.rest.model.SimplifyServerModel;
import org.fanjr.simplify.rest.storage.SimplifyBeanBuilderStorage;
import org.fanjr.simplify.rest.utils.SimplifyMvcMappingUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 
 * @author fanjr@vip.qq.com
 * @since 20190222 10:29:28
 */
public class SimplifyServerPostProcessor implements BeanPostProcessor {

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		SimplifyServerModel model = SimplifyBeanBuilderStorage.INSTANCE.getServerModel(beanName);
		if (null != model) {
			model.setInstance(bean);
			SimplifyMvcMappingUtil.addMapping(model);
		}
		return bean;
	}

}
